<?php
namespace Components\Staff\Sha\Notice;

class Logic {
  protected function getPaginate($builder, $limit, $page) {
    return ['code' => 0, 'pager'=>(new \Phalcon\Paginator\Adapter\QueryBuilder([
      'builder' => $builder,
      'limit' => $limit,
      'page' => $page
    ])) -> getPaginate()];
  }

  public function pager($limit, $page) {
    $builder = (new \Phalcon\Mvc\Model\Query\Builder())
      -> from([
        'staff_acl_roles' => __NAMESPACE__ . '\\Model',
      ])
      -> orderBy('staff_acl_roles.id DESC');

    $res = $this -> getPaginate($builder, $limit, $page);
    $items = [];
    foreach($res['pager'] -> items as $k => $staff) {
      $items[$k] = ['staff_acl_roles' => $staff];
    }
    $res['pager'] -> items = $items;

    return $res;
  }
}
